package org.chnxi.study.springcloud.dubbo.order.controller;

import org.apache.dubbo.config.annotation.Reference;
import org.chnxi.study.springcloud.dubbo.storage.service.IDubboService;
import org.chnxi.study.springcloud.dubbo.storage.service.IStorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Service;

public abstract class BaseController<T extends IDubboService> {

    @Autowired
    //@Reference(timeout = 1000, version = "1.0.0", retries = 0, check = false)
    private T t;

    public T getDubboService(){
        return t;
    }

}

interface IApi{}

abstract class Base<T extends IApi>{
    @Autowired
    T t;
    public T getT(){return t;}
}

interface OrderApi extends IApi{
    void viewOrder();
}

@Service
class OrderLogic extends Base<OrderApi>{
    public void orderMethod(){
        super.getT().viewOrder();
    }
}

interface UserApi extends  IApi{
    void viewUser();
}

@Service
class UserLogic extends Base<UserApi>{
    public void userMethod(){
        super.getT().viewUser();
    }
}

@Configuration
class SpringCfg{

    @Bean
    public OrderApi createOrderApi(){
        return new OrderApi() {
            @Override
            public void viewOrder() {
                System.out.println("order");
            }
        };
    }

    @Bean
    public UserApi createUserApi(){
        return new UserApi() {
            @Override
            public void viewUser() {
                System.out.println("user");
            }
        };
    }

}